<%--
  Created by IntelliJ IDEA.
  User: 曹家润
  Date: 2024/11/9
  Time: 17:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Spring MVC实验页面</title>
</head>
<body>
<h2>Spring MVC实验页面</h2>
<button id="fetchDataButton">点击查看Hello Spring MVC</button>
<div id="responseContainer"></div>

<script>
    document.getElementById("fetchDataButton").addEventListener("click", function () {
        fetch("hello")
            .then(response => {
                if (!response.ok) {
                    throw new Error('请求失败，状态码：' + response.status);
                }
                return response.text(); // 处理为文本类型
            })
            .then(data => {
                document.getElementById("responseContainer").innerText = data; // 将数据展示在页面上
            })
            .catch(error => {
                console.error('请求错误:', error);
                document.getElementById("responseContainer").innerText = "请求失败，请稍后重试。";
            });
    });
</script>
</body>
</html>


